/*
 * 创建时间：17-9-23
 * 作者：sce
 * 功能描述：毕业去向的model表
 * 修改时间：
 */

import Sequelize from 'sequelize'
import sequelize from './../../database'

const Excellent = sequelize.define('sys_excellent', {
    id:{
        type: Sequelize.UUIDV4,
        defaultValue: Sequelize.UUIDV4,
        unique: true,
        allowNull: false,
        primaryKey:true
    },
    name:{
        type:Sequelize.STRING,
        allowNull:false
    },
    edu_background:{
        type:Sequelize.STRING,
        allowNull:false
    },
    gradu_goto:{
        type:Sequelize.STRING,
        allowNull:false
    },
    message:{
        type: Sequelize.STRING,
        allowNull:false
    },
    picture_url:{
        type:Sequelize.STRING
    },
    field:{
        type: Sequelize.STRING,
        allowNull:false
    },
    is_publish:{
        type: Sequelize.INTEGER,
        defaultValue:1,
        allowNull:false
    }
},{
    freezeTableName:false,
    tableName: 'sys_excellent',
    createdAt:'created_at',
    updatedAt:'updated_at'
});
class ExcellentModel{
    findById(id){
        return Excellent.findById(id);
    }
    findListAll(){
        return Excellent.findAll();
    }
    findListPublish(){
        return Excellent.findAll({
            where:{
                is_publist:1
            }
        })
    }
    findByPage(record){
        return Excellent.findAndCount({
            limit:record.page_size,
            offset: record.page_size * (record.page_no -1)
        })
    }
    insert(record){
        return Excellent.create(record);
    }
    update(record){
        return Excellent.update(record,
            {
                'where':{
                    'id': record.id
                }
            }
        )
    }
    deleteById(id){
        return Excellent.destroy({
            where: {
                id: id
            }
        });
    }
}
module.exports = new ExcellentModel();